<div class="bg-light lter b-b wrapper-md">
  <h1 class="m-n font-thin h3">转码任务管理</h1>
</div>
<div class="wrapper-md">

  <div class="panel panel-default">
    <div class="panel-heading">
      转码任务管理
    </div>
    <div>
      <div  ng-controller="dataTablesCtrl">
        <div class="row">
          <div class="col-sm-12" >
            <div class="panel-heading">
              <a href="javascript:void(0);" ng-click="goRemove();" ><button class="btn btn-default btn-sm "><i class="fa fa-trash-o fa-lg"></i>&nbsp; 删除</button></a>
            <!--隐藏域-->
            <input type="hidden" id ="optIds" name="optIds">
            </div>
          </div>
        </div>
      <table id="myTable" class="table table-striped m-b-none"></table>
      </div>
    </div>
  </div>




<script type="text/javascript" >

function checkOne(){
  var optIds = '';
  $("input[name='ids']:checkbox:checked").each(function(){ 
      optIds+=$(this).val() +',';
       });
   if(''!=optIds){
        optIds = optIds.substring(0,optIds.length-1);
      }
$('#optIds').val(optIds);

  console.log($('#optIds').val());
}


//angularjs总控制器
app.controller('dataTablesCtrl', function($scope, $http,$state) {
   
//进入编辑页面
   $scope.goRemove = function () {
  var optIds = $('#optIds').val();
     if(''==optIds){
    top.layer.msg('请至少选择一项', {icon: 6});
       return false;
    }

    top.layer.confirm('您确定删除这些信息吗', function(index){
    $.ajax({
      url : '',
      type : 'post',
      data : {
        ids:optIds
      },
      cache : false,
      success : function(data) {
        top.layer.msg('操作成功', {icon: 6});
      }
    });
    top.layer.close(index);
  });
    };
});

var dtUrl = API_URL+"task_file_transcode?query=delflag:0";

$(document).ready(function(){

    $('#myTable').dataTable({      
        ajax: {
        url: dtUrl,  
          success:function(json){
            //清空表格
            $('#myTable').dataTable().fnClearTable();  
            if(null==json){
              $('#myTable').dataTable().fnClearTable();  
             }else{
               $('#myTable').dataTable().fnAddData(json,true);  //刷下表格
             }  
          }
        },

    deferRender:true,
    Processing:true,
    aaSorting: [[4, "desc"]],
    buttons: [{
      extend: 'collection',
      text: 'Export',
      buttons: [ 'csv-flash', 'xls-flash', 'pdf-flash' ]
    }],
            //默认最后一列（最后更新时间）降序排列
    order: [[5, "desc"]],     
      //行创建完成后回调
      rowCallback: function (row, data, index) {
         
      },
      aoColumns: [
      {
        data : "Id",
        title: "<input type='checkbox' id='allChecked' name='allChecked' />",
        orderable: false , 
        render : function(data, type, full, meta) {
        return '<input type="checkbox" value="'+ data + '" name="ids" onclick="checkOne()"/>';
        }
      },
      { data: "Id",
        title: "ID"
      },
      { data: "InputFileDirectory" ,
        title: "文件目录"
      },
      { data: "InputFileName" ,
        title: "输入文件名"
      },
      { data: "InputFileExtName",
        title: "输入扩展名"
      },
      { data: "OutputFileName" ,
        title: "输出文件名"
      },
      { data: "OutputFileExtName" ,
        title: "输出扩展名"
      },
      { data: "TaskStatus" ,
        title: "任务状态"
      },
      { data: "TaskPercent" ,
        title: "任务进度"
      },
        
      { data: "UpdateTime"   ,
        title: "更新时间",
          render: function (data, type, row, meta) {
            return getDateTime(data);
          }
      }
     ],
      columnDefs: [
        {
          targets:6,
          data: null,
          title: "操作",
          render: function (data, type, row, meta) {
            var href = '';
              href += "&nbsp;  <a href='#/app/user/user/edit/"+row.Id+"'>";
              href += "<i  title='编辑' class='fa fa-edit fa-lg'></i></a>";    
              href += "&nbsp;  <a href='javascript:void(0);' onclick=goDelete("
                + row.Id+ ")>";
              href += "<i  title='删除' class='fa fa-trash-o fa-lg'></i></a>";
              return href;
          }
        },
       
      ],
      drawCallback: function( settings ) {
         

           },

      initComplete:function(data){
        //选中行
        $('#myTable tbody').on( 'click', 'tr', function () {
          if ( $(this).hasClass('selected') ) {
            $(this).removeClass('selected');
          }
          else {
            table.$('tr.selected').removeClass('selected');
              $(this).addClass('selected');
          }                
        });

        //全选、反选
        $('#allChecked').on('click' , function(){
          var boxes = document.getElementsByName("ids");
            for(i=0;i<boxes.length;i++){
                        boxes[i].checked = this.checked;
            }
            var optIds ='';
            if(this.checked){
              $("input[name='ids']:checkbox:checked").each(function(){ 
                 optIds+=$(this).val() +',';
               });
            }else{
              optIds='';
            }
            if(''!=optIds){
              optIds = optIds.substring(0,optIds.length-1);
            }
            $('#optIds').val(optIds);
        });
      },
      Paginate: true, 
      language:{
      url: 'vendor/jquery/datatables/Chinese.json'
      }
    });
  });  


</script>